package com.onecar.carplatform.common.protocol.jt808;

import com.onecar.carplatform.common.constants.Jt808Const;
import com.onecar.carplatform.common.constants.Jt808MsgId;
import com.onecar.carplatform.common.protocol.annotations.JtMsgDesc;
import com.onecar.carplatform.common.protocol.basics.JtMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.ReferenceCountUtil;
import lombok.Data;
import lombok.ToString;

/**
 * @Author : ljq
 * @Description :
 * @Date : 2021/8/23 19:56
 * @Version : 1.0
 */
@Data
@ToString(callSuper = true)
@JtMsgDesc(msgId = Jt808MsgId.TERMINAL_REGISTER_RESPONSE)
public class Jt808Msg8100 extends JtMessage {

    private int responseSerialId; // 应答流水号
    private byte result; // 结果 0：成功；1：车辆已被注册；2：数据库中无该车辆；3：终端已被注册；4：数据库中无该终端
    private String authCode; // 鉴权码

    @Override
    public byte[] encodeMsgBody() {
        ByteBuf msgBody = ByteBufAllocator.DEFAULT.heapBuffer(3 + authCode.length());
        msgBody.writeShort(responseSerialId);
        msgBody.writeByte(result);
        msgBody.writeBytes(authCode.getBytes(Jt808Const.DEFAULT_CHARSET));
        byte[] msgBodyArr = new byte[msgBody.readableBytes()];
        msgBody.readBytes(msgBodyArr);
        ReferenceCountUtil.release(msgBody);
        return msgBodyArr;
    }

    @Override
    public void decodeMsgBody(ByteBuf buf){

    }
}
